package com.diy.sigmund.diyuser.test.controller;


import com.diy.sigmund.diycommon.spring.listener.SessionListener;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author ylm-sigmund
 * @since 2020/9/14 13:32
 */
@RestController
@RequestMapping("sessionRestController")
public class SessionRestController {

    private static final Logger log = LoggerFactory.getLogger(SessionRestController.class);

    @Autowired
    private SessionRestController sessionRestController;

    @PostMapping("hello")
    public String hello(HttpServletRequest httpServletRequest) {
        log.info(sessionRestController.getSession(httpServletRequest));
        return "hello";
    }

    @GetMapping("getSession")
    public String getSession(HttpServletRequest httpServletRequest) {
        return httpServletRequest.getSession().getAttribute(SessionListener.COUNT).toString();
    }
}
